<template>
    <div class="comment-list">
        <div class="avatar">
            <img :src="item.avatarUrl"/>
        </div>
        <div class="detial">
            <div class="nm-like">
                <div class="nm-score">
                    <div class="nm">
                        <span>{{item.nick}}</span>
                        <i :class="`lv${item.userLevel}`"></i>
                    </div>
                    <div class="score">
                        <span>{{item.score}}分</span>
                        <div>购票</div>
                    </div>
                </div>
                <div class="like" :style="{'color':liked?'red':'#999','border-color':liked?'red':'#ddd'}" @click="changelike">
                    <i class="iconfont icon-dianzan"></i>
                    <!-- &nbsp; -->
                    <span>{{item.upCount}}</span>
                </div>
            </div>
            <div class="article">
                <p :class="[close?'close':'']" @click="close=!close">{{item.content}}</p>
            </div>
            <div class="time">
                <span>{{item.time|filtime}}</span>
                <div>{{item.replyCount}}&nbsp;回复</div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props:{
        item:Object,
    },
    data(){
        return{
            close:true,
            liked:false,
        }
    },
    methods:{
        changelike(){
            this.liked=!this.liked;
            if(this.liked){
                this.$emit('upCount',{commentId:this.item.id,liked:true});
            }else{
                this.$emit('upCount',{commentId:this.item.id,liked:false});
            }
        }
    },
    filters:{
        filtime(time){
            let date=new Date(time);
            let m=date.getMonth()+1;
            let d=date.getDate();
            m=m<10?'0'+m:m;
            d=d<10?'0'+d:d;
            return m+"-"+d;
        },
    },
}
</script>

<style lang="less" scoped>
.comment-list{
    padding: 15px;
    padding-right: 0;
    display: flex;

    .avatar{
        width: 34px;
        height: 34px;
        border-radius: 50%;
        overflow: hidden;

        img{
            display: block;
            width: 100%;
        }
    }

    .detial{
        flex: 1;
        margin-left: 10px;
        padding-right: 15px;
        position: relative;
        font-size: 12px;

        &::after{
            content: "";
            width: 100%;
            position: absolute;
            bottom: -15px;
            left: 0;
            border-bottom: 1px solid #eee;
        }

        .nm-like{
            display: flex;
            justify-content: space-between;

            .nm{
                i{
                    margin-left: 8px;
                    display: inline-block;
                    width: 36px;
                    height: 16px;
                    vertical-align: sub;

                    &.lv2{
                        background: url(../assets/lv2.png) no-repeat;
                        background-size: contain;
                    }

                    &.lv3{
                        background: url(../assets/lv3.png) no-repeat;
                        background-size: contain;
                    }
                }
            }

            .score{
                padding-top: 3px;
                span{
                    color: #faaf00;
                }

                div{
                    display: inline-block;
                    color: #4f89b3;
                    padding: 3px 7px;
                    position: relative;
                    transform: scale(.8);

                    &::after{
                        content: "";
                        position: absolute;
                        width: 100%;
                        height: 100%;
                        left: 0;
                        top: 0;
                        border-radius: 15px;
                        border: 1px solid #4f89b3;
                    }
                }
            }
        }

        .like{
            padding: 5px 8px;
            border: 1px solid #ddd;
            border-radius: 25px;
            line-height: 16px;
            height: 16px;
            color: #999;

            i{
                font-size: 14px;
                margin-right: 7px;
            }
        }

        .article{
            padding: 10px 0;
            font-size: 15px;
            color: #222;
            line-height: 22px;

            p.close{
                display: -webkit-box;
                -webkit-line-clamp: 5;
                -webkit-box-orient: vertical;
                overflow: hidden;
                text-overflow: ellipsis;
            }
        }

        .time{
            color: #666;

            div{
                display: inline-block;
                color: #4f89b3;
                padding: 3px 8px;
                margin-left: 10px;
                height: 16px;
                line-height: 16px;
                background-color: #4f89b32c;
                border-radius: 10px;
            }
        }
    }
}
</style>